Ninja Database Pro
Optimizing Performance
Basic Tasks > Optimizing Performance

Ninja Database Pro has several built in features to assist you with achieving an application that performs to the end users expectation. 

 

·         Primary Keys – Loading a type from the primary key is the fastest way to retrieve an item.

·         Transactions – A flush is performed after each individual record is saved to prevent database corruption.  When there is a long list of items to be saved, use a transaction.  There is overhead beginning and committing a transaction.  You will need to test which is the fastest for your project. 

·         Indexes – Increase the performance of your application by creating an index on a commonly queried property.  Create an index by calling the AddIndex method.  Create a query on the index by calling the CreateIndexQuery method.  Each index takes memory when querying for that type.  Do not create indexes on large string properties or you might run out of memory on Windows Phone 7.  Windows Phone 7 has a limit of 90MB of memory for your application.  You will need to balance memory and performance.  You can always perform queries by using LINQ.  See the CreateObjectQuery method.

·         Bulk Delete – To delete a large number of records efficiently, pass an array of primary keys into the Delete method.

·         Save List – Save your list of changes by creating IsDirty and IsDeleted properties in your classes.  Only items that are dirty will be saved.  See the IsDirty property for more information.

·         Bulk Operation – For inserting or updating thousands of records, use the BeginBulkOperation and CommitBulkOperation.

·         Pack – As records are updated and deleted space is recovered automatically using a best unused space algorithm.  Periodically doing a pack will eliminate all the unused space in your database making it faster.

·         Turn off Encryption and Compression – Encrypting or compressing your data will take extra time to load and save your data.  You can turn off encryption and compression at any time.  Existing records will continue to stay encrypted or compressed until the next time they are updated.  See the DataFormat property. 

·         Object Children vs Relational Children – Child and parent objects can either be saved together with the current object or they can be saved as separate tables.  Decide up front how to save your objects based on your domain model.  See Object Children vs Relational Children.  Implementing IsDirty on child objects will also improve performance.

·         Increase the Cache Size – By default, indexes and objects are automatically cached when loaded.  Increase the cache size to improve performance.